home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / i / internet / software / ftpsrvsr / cookie.c next >
Encoding:
C/C++ Source or Header  |  1991-06-09  |  1.6 KB  |  71 lines

  1. #include <stdlib.h>
  2. #include <tos.h>
  3. #include "cookie.h"
  4.  
  5. #define NULL (void *)0L
  6. #define _cookiejar    *(long *)0x5A0L
  7.  
  8.  
  9. COOKIE *new_cookiejar(long n)
  10. {
  11.   register long superstack;
  12.   register COOKIE *jar,*newjar;
  13.   register long i,c;
  14.  
  15.   jar = get_cookiejar();
  16.   i=0;
  17.   if(jar) for(; jar[i].id != ENDCOOKIE; i++);  /* get size of old jar */
  18.   if(jar && jar[i].val > n) return(jar);  /* there isroom in jar */
  19.  
  20.   newjar = (COOKIE *)malloc(n*sizeof(COOKIE));/* alloc new jar */
  21.   if(jar && newjar) for(c=0; c<i; c++)
  22.   {  /* copy old jar */
  23.     newjar[c].id = jar[c].id;
  24.     newjar[c].val = jar[c].val;
  25.   }
  26.   newjar[i].id = ENDCOOKIE;  /* terminate new jar */
  27.   newjar[i].val = n;
  28.   superstack = Super((void *)0);
  29.   _cookiejar = (long)newjar;  /* install new jar */
  30.   Super((void*)superstack);
  31.   return(newjar);
  32. }
  33.  
  34. COOKIE *get_cookiejar(void)
  35. {
  36.   register long superstack;
  37.   register COOKIE *jar;
  38.  
  39.   superstack = Super((void *)0);
  40.   jar = (COOKIE *)_cookiejar;  /* return address of cookiejar */
  41.   Super((void*)superstack);
  42.   return(jar);
  43. }
  44.  
  45.  
  46. COOKIE *add_cookie(long id,long val)
  47. {
  48.   register COOKIE *jar;
  49.   if((jar = new_cookiejar(8L))==NULL) return(NULL);
  50.   while(jar->id != ENDCOOKIE) jar++;  /* search end of cookiejar */
  51.   jar->id = id;
  52.   (jar+1)->val = jar->val;  /* keep size of jar */
  53.   jar->val = val;
  54.   (jar+1)->id = ENDCOOKIE;
  55.   return(jar);
  56. }
  57.  
  58.  
  59. COOKIE *get_cookie(long id)
  60. {
  61.   register COOKIE *jar;
  62.   if((jar = get_cookiejar()) == NULL) return(NULL);
  63.   while(jar->id)
  64.   {
  65.     if(jar->id == id) return(jar);  /* find cookie */
  66.     jar++;
  67.   }
  68.   return(NULL);
  69. }
  70.  
  71.